﻿'Description:文档查看类
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:Wangjh
'create Date:2018-12-26
'Rewriter:
'Rewrite Date:
Imports BusinessRule.IBusiness
Imports DatabaseAccess.DBUtility

Public Class uLMSDocumetViewBusiness
    Implements uLMSDocumetViewIBusiness
    ''' <summary>
    ''' 获取对象表的附件信息
    ''' add:Wangjh 20181226
    ''' </summary>
    ''' <param name="tableName"></param>
    ''' <param name="ID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetObjectDoc(ByVal tableName As String, ByVal ID As String) As DataTable Implements uLMSDocumetViewIBusiness.GetObjectDoc
        Dim strSql As String = ""
        Dim value As String = ""
        If tableName = "Spec" Then
            value = ID.Split("-").Last
        Else
            value = ID
        End If
        '1.获取数据库中的附件
        strSql = "SELECT DISTINCT SUBSTR(doc.identifier,INSTR(doc.Identifier,'\',-1)+1) documentname,REPLACE( SUBSTR(doc.identifier,INSTR(doc.Identifier,'Temp\')),'\','/') filepath,1 type FROM " + tableName + " t "
        strSql += <string>LEFT JOIN Documententry dt ON dt.documentsetid=t.documentsetid
                    LEFT JOIN DOCUMENTbase dtb ON dtb.documentbaseid=dt.documentbaseid
                    LEFT JOIN DOCUMENT doc ON doc.documentid=NVL(dtb.revofrcdid,dt.documentid)
                    LEFT JOIN  DOCUMENTbase dtb2 ON dtb2.documentbaseid=doc.documentbaseid</string>.Value
        strSql += " WHERE dtb2.documentname is not null and  t." + tableName + "ID='" + value + "'"
        Dim dt2 As DataTable = DatabaseHelper.Query_ReturnDatTable(strSql)
        '1.1获取路径中的附件
        strSql = String.Format(<string>select distinct t.filename documentname,t.filepath ,1 type  from objectdocinfo t where t.parentid='{0}'</string>.Value,
                               value)
        dt2.Merge(DatabaseHelper.Query_ReturnDatTable(strSql))
        '2.获取数据库中的URL地址
        If tableName = "Spec" Then
            value = ID.Split("-").First
            tableName = "WorkflowStep"
        End If
        strSql = "SELECT DISTINCT PD.FILENAME documentname,pd.FILEURLLINK filepath,2 type FROM " + tableName + " t "
        strSql += " LEFT JOIN PDMURLRECORD PD ON PD.PARENTID=t." + tableName + "ID"
        strSql += " WHERE PD.FILENAME is not null and t." + tableName + "ID='" + value + "'"
        Dim dt1 As DataTable = DatabaseHelper.Query_ReturnDatTable(strSql)
        dt1.Merge(dt2)
        dt1.AcceptChanges()
        Return dt1
    End Function

End Class
